package oldreturn

import (
	"fmt"
	"net/http"

	"oldReturn/src/httpserver"

	"github.com/gin-gonic/gin"
)

func init() {
	err := httpserver.Register("/IsOld", IsOld)
	if err != nil {
		fmt.Println(err)
	}
}

var IsOld = func(c *gin.Context) {
	var user UserParam
	if err := c.ShouldBindJSON(&user); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误！"})
		return
	}
	isold, _, err := CheckUserIsOld(user)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": "系统错误！"})
		return
	}
	if isold {
		c.JSON(http.StatusOK, gin.H{"isold": true})
	} else if !isold {
		c.JSON(http.StatusOK, gin.H{"isold": false})
	}
}
